import axios from "@/utils/requestdp";
let aaa = {
  data() {
    return {
      dnoptions: [],
      dnval: []
    };
  },
  watch: {},
  mounted() {
    //gis操作存储
    this.switchrelizhan =
      this.initlocal("switchrelizhan") == "true" ? true : false;
    this.$root.switchrelizhan = this.switchrelizhan;
    this.switchguanjing =
      this.initlocal("switchguanjing") == "true" ? true : false;
    this.$root.switchguanjing = this.switchguanjing;

    let reqdn = axios.get("/model/pipeline/dn");
    reqdn.then(res => {

      let resdnvals = []
      res.data.map(item => {
        this.dnoptions.push({ label: item.dnvalue, value: item.dnvalue });
        resdnvals.push(item.dnvalue)
      });

      if (!this.initlocal("dnvals")) {
        this.setlocal('dnvals',resdnvals,true)
        this.dnval = resdnvals
      }else{
        resdnvals = this.initlocal("dnvals",true)
        this.dnval = resdnvals
      }
      
    });
  },
  methods: {
    dntypechange() {
      this.setlocal('dnvals', this.dnval, true)
    },
    switchguanjing1() {
      let _this = this;
      let viewer = this.$root._earth.czm.viewer;
      this.setlocal("switchguanjing", this.switchguanjing);
      this.$root.switchguanjing = this.switchguanjing;

      if (this.switchguanjing) {
        if (_.has(this.$root, "dsgis")) {
          let guanjinglabels = viewer.scene.primitives.add(
            new Cesium.LabelCollection()
          );

          this.guanjinglabels = guanjinglabels;

          let entities = this.$root.dsgis.entities.values;

          console.log(this.dnval);

          for (var o = 0; o < entities.length; o++) {
            var entity = entities[o];
            if (entity.id.split(".")[0] == "pipeline") {
              entity.position =
                entity.polyline.positions._value[
                  entity.polyline.positions._value.length / 2
                ];
              if (_.has(entity.position, "_value")) {
                if (_.has(entity.properties,'dn') && this.dnval.indexOf(entity.properties.dn._value) != -1) {

                  if (entity.properties.dn._value.indexOf("DN") == -1) {
                    entity.properties.dn._value =
                      "DN" + entity.properties.dn._value;
                  }

                  guanjinglabels.add({
                    position: entity.position._value,
                    // text: 'DN',
                    text: entity.properties.dn._value,
                    font: _this.getscalepxcnum(20) + "px sans-serif",
                    pixelOffset: new Cesium.Cartesian2(
                      _this.getscalepxcnum(20),
                      0
                    ),
                    fillColor: Cesium.Color.fromCssColorString("#FFFF2D"),
                    showBackground: true,
                    backgroundColor: Cesium.Color.fromCssColorString("#0D2654"),
                    scale: 1.0,
                    backgroundPadding: new Cesium.Cartesian2(
                      2 * _this.$store.state.daping.scale,
                      1.5 * _this.$store.state.daping.scale
                    ),
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
                      10.0,
                      4000.0 * _this.$store.state.daping.scale
                    ),
                    scaleByDistance: new Cesium.NearFarScalar(
                      500.0,
                      1.0,
                      5000.0 * _this.$store.state.daping.scale,
                      0.001
                    )
                  });
                }
              }
            }
          }
        }
      } else {
        if (_.has(this, "guanjinglabels")) {
          this.guanjinglabels.destroy();
        }
      }
    },
    switchrelizhan1() {
      let _this = this;
      let viewer = this.$root._earth.czm.viewer;
      this.setlocal("switchrelizhan", this.switchrelizhan);
      this.$root.switchrelizhan = this.switchrelizhan;

      if (this.switchrelizhan) {
        if (_.has(this.$root, "dsgis")) {
          let relizhanlabels = viewer.scene.primitives.add(
            new Cesium.LabelCollection()
          );
          _this.relizhanlabels = relizhanlabels;
          let entities = this.$root.dsgis.entities.values;

          for (var o = 0; o < entities.length; o++) {
            var entity = entities[o];
            if (
              entity.id.split(".")[0] == "heatplant" ||
              entity.id.split(".")[0] == "substation"
            ) {
              relizhanlabels.add({
                position: entity.position._value,
                text: entity.properties.name._value,
                font: this.getscalepxcnum(20) + "px sans-serif",
                pixelOffset: new Cesium.Cartesian2(0, this.getscalepxcnum(-10)),
                fillColor: Cesium.Color.fromCssColorString("#A0c8DB"),
                showBackground: true,
                backgroundColor: Cesium.Color.fromCssColorString("#0D2654"),
                scale: 1.0,
                backgroundPadding: new Cesium.Cartesian2(
                  2 * this.$store.state.daping.scale,
                  1.5 * this.$store.state.daping.scale
                ),
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
                  10.0,
                  4000.0 * this.$store.state.daping.scale
                ),
                scaleByDistance: new Cesium.NearFarScalar(
                  500.0,
                  1.0,
                  5000.0 * this.$store.state.daping.scale,
                  0.001
                )
              });
            }
          }
        }
      } else {
        if (_.has(this, "relizhanlabels")) {
          this.relizhanlabels.destroy();
        }
      }
    }
  }
};

export default aaa;
